#ifndef __DRV_W25Q128_H
#define __DRV_W25Q128_H
#ifdef __cplusplus
  extern "C" {
#endif


#include "main.h"


typedef struct
{
uint8_t		UniqID[8];
uint16_t	PageSize;
uint32_t	PageCount;
uint32_t	SectorSize;
uint32_t	SectorCount;
uint32_t	BlockSize;
uint32_t	BlockCount;
uint32_t	CapacityInKiloByte;
uint8_t		StatusRegister1;
uint8_t		StatusRegister2;
uint8_t		StatusRegister3;
uint8_t		Lock;
}w25q128_t;


extern w25q128_t	w25q128;


uint32_t		W25Q128_Init(void);

void		W25Q128_EraseChip(void);
void 		W25Q128_EraseSector(uint32_t SectorAddr);
void 		W25Q128_EraseBlock(uint32_t BlockAddr);

uint32_t	W25Q128_PageToSector(uint32_t PageAddress);
uint32_t	W25Q128_PageToBlock(uint32_t PageAddress);
uint32_t	W25Q128_SectorToBlock(uint32_t SectorAddress);
uint32_t	W25Q128_SectorToPage(uint32_t SectorAddress);
uint32_t	W25Q128_BlockToPage(uint32_t BlockAddress);

uint32_t 		W25Q128_IsEmptyPage(uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_PageSize);
uint32_t 		W25Q128_IsEmptySector(uint32_t Sector_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_SectorSize);
uint32_t 		W25Q128_IsEmptyBlock(uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_BlockSize);

void 		W25Q128_WriteByte(uint8_t pBuffer, uint32_t Bytes_Address);
void 		W25Q128_WritePage(uint8_t *pBuffer, uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_PageSize);
void 		W25Q128_WriteSector(uint8_t *pBuffer, uint32_t Sector_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_SectorSize);
void 		W25Q128_WriteBlock(uint8_t* pBuffer, uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_BlockSize);

void 		W25Q128_ReadByte(uint8_t *pBuffer, uint32_t Bytes_Address);
void 		W25Q128_ReadBytes(uint8_t *pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead);
void 		W25Q128_ReadPage(uint8_t *pBuffer, uint32_t Page_Address,uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_PageSize);
void 		W25Q128_ReadSector(uint8_t *pBuffer, uint32_t Sector_Address,uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_SectorSize);
void 		W25Q128_ReadBlock(uint8_t* pBuffer, uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_BlockSize);


#ifdef __cplusplus
  }
#endif
#endif /* __DRV_W25Q128_H */
